package com.honghe.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.honghe.system.domain.Cases;
import com.honghe.common.core.domain.entity.SysUser;
import com.honghe.system.mapper.CasesMapper;
import com.honghe.system.service.ICasesService;
import com.honghe.system.service.ISysUserService;

/**
 * 客户案件Service业务层处理
 * 
 * @author honghe
 */
@Service
public class CasesServiceImpl implements ICasesService
{
    @Autowired
    private CasesMapper casesMapper;

    @Autowired
    private ISysUserService userService;

    /**
     * 查询客户案件列表
     * 
     * @param cases 客户案件信息
     * @return 客户案件集合
     */
    @Override
    public List<Cases> selectCasesList(Cases cases)
    {
        return casesMapper.selectCasesList(cases);
    }

    /**
     * 新增客户案件
     * 
     * @param cases 客户案件信息
     * @return 结果
     */
    @Override
    public int insertCases(Cases cases)
    {
        return casesMapper.insertCases(cases);
    }

    /**
     * 修改客户案件
     * 
     * @param cases 客户案件信息
     * @return 结果
     */
    @Override
    public int updateCases(Cases cases)
    {
        return casesMapper.updateCases(cases);
    }

    /**
     * 删除客户案件信息
     * 
     * @param caseId 客户案件ID
     * @return 结果
     */
    @Override
    public int deleteCasesByCaseId(Long caseId)
    {
        return casesMapper.deleteCasesByCaseId(caseId);
    }

    /**
     * 批量删除客户案件信息
     * 
     * @param caseIds 需要删除的客户案件ID
     * @return 结果
     */
    @Override
    public int deleteCasesByCaseIds(Long[] caseIds)
    {
        return casesMapper.deleteCasesByCaseIds(caseIds);
    }

    /**
     * 查询客户案件信息
     * 
     * @param caseId 客户案件ID
     * @return 客户案件信息
     */
    @Override
    public Cases selectCasesByCaseId(Long caseId)
    {
        return casesMapper.selectCasesByCaseId(caseId);
    }

    /**
     * 分配案件
     *
     * @param caseId 案件ID
     * @param assignedUserId 被分配用户ID
     * @return 结果
     */
    @Override
    @Transactional
    public int assignCase(Long caseId, Long assignedUserId)
    {
        Cases cases = new Cases();
        cases.setCaseId(caseId);
        cases.setAssignedUserId(assignedUserId);
        
        // 获取用户信息
        SysUser user = userService.selectUserById(assignedUserId);
        if (user != null)
        {
            cases.setAssignedUserName(user.getNickName());
        }
        
        return casesMapper.assignCase(cases);
    }
} 